﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Business.WEB;
using DataAccess.Exceptions;
using Presenters.WEB.Views;

namespace Presenters.WEB
{
    public class LoginPresenter
    {
        public ILoginView View { get; set; }
        public bool userExists { get; set; }

        public LoginPresenter(ILoginView view)
        {
            this.View = view;
            this.userExists = false;
        }
        
        public void SubmitLogin()
        {
            try
            {
                LoginManager lgm = new LoginManager();
                lgm.Login(this.View.username, this.View.password);
                this.userExists = true;
            }
            catch (ValidationException v_ex)
            {
                this.View.Message = v_ex.Message;
            }
            catch (BusinessException b_ex)
            {
                this.View.Message = b_ex.Message;
            }
            
            catch (Exception ex)
            {
                this.View.Message = "Error desconocido.";
            }
        }
        public void SubmitLoginWEB()
        {
            try
            {
                LoginManager lgm = new LoginManager();
                lgm.LoginWEB(this.View.username, this.View.password);
                this.userExists = true;
            }
            catch (ValidationException v_ex)
            {
                this.View.Message = v_ex.Message;
            }
            catch (BusinessException b_ex)
            {
                this.View.Message = b_ex.Message;
            }

            catch (Exception ex)
            {
                this.View.Message = "Error desconocido.";
            }
        }
        
    }
}
